package com.atguigu.tingshu.user.api;

import com.atguigu.tingshu.common.anno.GuiguLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.util.AuthContextHolder;
import com.atguigu.tingshu.user.service.UserListenProcessService;
import com.atguigu.tingshu.vo.user.LastUserListenPlayVo;
import com.atguigu.tingshu.vo.user.UserListenProcessVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

@Tag(name = "用户声音播放进度管理接口")
@RestController
@RequestMapping("api/user/userListenProcess")
@SuppressWarnings({"unchecked", "rawtypes"})
public class UserListenProcessApiController {

	@Autowired
	private UserListenProcessService userListenProcessService;

	@GuiguLogin
	@Operation(summary = "更新播放进度")
	@PostMapping("/updateListenProcess")
	public Result updateListenProcess(@RequestBody UserListenProcessVo  userListenProcessVo){
		Long userId = AuthContextHolder.getUserId();
		userListenProcessService.updateListenProcess(userId,userListenProcessVo);
		return Result.ok();

	}

	///api/user/userListenProcess/getTrackBreakSecond/{trackId}
	@GuiguLogin
	@Operation(summary = "获取声音上一次播放进度")
	@GetMapping(value = "getTrackBreakSecond/{trackId}")
	public Result<BigDecimal> getTrackBreakSecond(@PathVariable(name = "trackId") Long trackId){
		BigDecimal bigDecimal = userListenProcessService.getTrackBreakSecond(trackId);
		return Result.ok(bigDecimal);
	}

	///api/user/userListenProcess/getLatelyTrack
	@GuiguLogin
	@Operation(summary = "获取最近一次播放声音")
	@GetMapping("/getLatelyTrack")
	public Result<LastUserListenPlayVo> getLatelyTrack(){
		LastUserListenPlayVo lastUserListenPlayVo = userListenProcessService.getLatelyTrack();
		return Result.ok(lastUserListenPlayVo);
	}
}

